﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class SideBlocksRepository : ISideBlocksRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<SideBlock> FindAll()
        {
            return entities.SideBlocks.AsQueryable();
        }

        public IQueryable<SideBlock> FindAllByLang(Language lang)
        {
            return entities.SideBlocks.Where(block => block.LanguageId == lang.Id).AsQueryable();
        }

        public SideBlock GetById(Int32 id)
        {
            return entities.SideBlocks.SingleOrDefault(block => block.Id == id);
        }

        public void Insert(SideBlock block)
        {
            entities.AddToSideBlocks(block);
        }

        public void Delete(SideBlock block)
        {
            entities.SideBlocks.DeleteObject(block);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
